package com.htsk.city.services.wechat.controller;

import com.htsk.city.services.core.domain.WxUser;
import com.htsk.city.services.core.entity.R;
import com.htsk.city.services.wechat.annotation.GetUserInfo;
import com.htsk.city.services.wechat.params.UserLoginParam;
import com.htsk.city.services.wechat.params.UserRegisterParam;
import com.htsk.city.services.wechat.service.UserService;
import com.htsk.city.services.wechat.service.WechatService;
import com.htsk.city.services.wechat.vo.UserInfoVO;
import com.htsk.city.services.wechat.vo.WxUserAddressVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("user")

public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("login")
    public R<String> login(@RequestBody UserLoginParam userLoginParam){
        return userService.login(userLoginParam);
    }

    @GetMapping("info")
    public R<UserInfoVO> userInfo(@GetUserInfo WxUser wxUser){
        return userService.getUserInfo(wxUser);
    }

    @PostMapping("edit")
    public R<Boolean> saveUserInfo(@GetUserInfo WxUser wxUser,@RequestBody UserInfoVO userInfo){
        return userService.saveUserInfo(wxUser,userInfo);
    }

    @PostMapping("register")
    public R<Boolean> register(@RequestBody UserRegisterParam userLoginParam){
        return userService.register(userLoginParam);
    }
    @GetMapping("listAddress")
    public R<List<WxUserAddressVO>> listAddress(@GetUserInfo WxUser wxUser){
        return userService.listAddress(wxUser);
    }

    @GetMapping("deleteAddress")
    public R<Boolean> deleteAddress(@GetUserInfo WxUser wxUser,@RequestParam("addressId")Long addressId){
        return userService.deleteAddress(wxUser,addressId);
    }

    @PostMapping("saveAddress")
    public R<Long> saveAddress(@GetUserInfo WxUser wxUser,@RequestBody WxUserAddressVO wxUserAddressVO){
        return userService.saveAddress(wxUser,wxUserAddressVO);
    }


    @GetMapping("sendSMS")
    public R<Boolean> sendSMS(@RequestParam("mobile")String mobile) throws Exception {
        return userService.sendSms(mobile);
    }
}
